// TouchC.cpp : Application for the calibrating process.
//

#include <windows.h>
#include <pwinuser.h>
#include <DebugZones.h>

#define REG_TOUCH_KEY	L"HARDWARE\\DEVICEMAP\\TOUCH"
#define REG_TOUCH_DATA	L"CalibrationData"


/// Main entry point application
int WINAPI WinMain (HINSTANCE hInstance, 
                    HINSTANCE hInstPrev, 
                    LPWSTR pCmdLine, 
                    int nCmdShow)
{
	// Register with debug subsystem
    RETAILREGISTERZONES(NULL);

    FUNC_ENTRY(L"hInstance = 0x%08X, hInstPrev = 0x%08X, pCmdLine = 0x%08X, nCmdShow = %d", hInstance, hInstPrev, pCmdLine, nCmdShow);
	
    // Assume we have to calibrate
    BOOL bCalibrate = TRUE;
	HKEY hKey;
    if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE, REG_TOUCH_KEY, 0, 0, &hKey) ) 
	{
        // If calibration data is already in the registry we don't want to calibrate again
        bCalibrate = (ERROR_SUCCESS != RegQueryValueEx(hKey, REG_TOUCH_DATA, NULL, NULL, NULL, NULL));
		// Cleanup
		RegCloseKey(hKey);
	}

    if (bCalibrate)
    {
        LOGMSG(ZONE_INFO, L"No calibration data, attempting to calibrate.\r\n");
        TouchCalibrate();
    }

    SignalStarted(_ttol(pCmdLine));

	FUNC_EXIT(L"%d", bCalibrate);
	return bCalibrate;
}
